import { GET_USER_INFO, TO_GENDER_ACTION, CHANGE_GENDER_MAN, CHANGE_GENDER_WOMEN, LOG_OUT, BG_DISAPPEAR } from "../types/SettingType"
import { getUserInfo, updateWomen, updateMen, logOut } from "../../data/set"
export const getUserInfoAction = () => {
  return async (dispatch) => {
    let res = await getUserInfo()
    let iconAppear
    if (res.data.gender === 'male') {
      iconAppear = 'man'
    } else if (res.data.gender === 'female') {
      iconAppear = 'women'
    } else {
      iconAppear = ''
    }
    dispatch({
      type: GET_USER_INFO,
      payload: {
        userMessage: res,
        iconAppear: iconAppear
      }
    })
  }
}
export const toGenderAction = () => {
  return (dispatch) => {
    dispatch({
      type: TO_GENDER_ACTION,
      payload: {}
    })
  }
}
export const GenderMenAction = () => {
  return async (dispatch) => {
    await updateMen()
    dispatch({
      type: CHANGE_GENDER_MAN,
      payload: {}
    })
  }
}
export const GenderWomenAction = () => {
  return async (dispatch) => {
    await updateWomen()
    let res = await getUserInfo()
    dispatch({
      type: CHANGE_GENDER_WOMEN,
      payload: {
        userMessage: res
      }
    })
  }
}

export const bgDisappearAction = () => {
  return async (dispatch) => {
    dispatch({
      type: BG_DISAPPEAR,
      payload: {
      }
    })
  }
}